package com.woniuxy.carlife.carlifeuserweb.controller;


import cn.hutool.core.util.ObjectUtil;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;

import com.woniuxy.carlife.carlifecommonsweb.util.CopyUtil;
import com.woniuxy.carlife.carlifecommonsweb.util.JwtUtil;
import com.woniuxy.carlife.carlifeusermodel.dto.ShippingaddressDto;
import com.woniuxy.carlife.carlifeusermodel.dto.ShoppingcartDto;
import com.woniuxy.carlife.carlifeusermodel.dto.UserCommentDto;
import com.woniuxy.carlife.carlifeusermodel.dto.UserInfoDto;
import com.woniuxy.carlife.carlifeusermodel.param.ShippingaddressParam;
import com.woniuxy.carlife.carlifeusermodel.param.UserInfoModifiedParam;
import com.woniuxy.carlife.carlifeusermodel.param.UserInfoParam;
import com.woniuxy.carlife.carlifeusermodel.param.Shoppingcartparam;
import com.woniuxy.carlife.carlifeuserweb.entity.Shippingaddress;
import com.woniuxy.carlife.carlifeuserweb.entity.Shoppingcart;
import com.woniuxy.carlife.carlifeuserweb.entity.Statistics;
import com.woniuxy.carlife.carlifeuserweb.entity.UserInfo;
import com.woniuxy.carlife.carlifeuserweb.service.ShippingaddressService;
import com.woniuxy.carlife.carlifeuserweb.service.ShoppingcartService;
import com.woniuxy.carlife.carlifeuserweb.service.StatisticsService;
import com.woniuxy.carlife.carlifeuserweb.service.UserInfoService;
import com.woniuxy.carlife.carlifeuserweb.util.StatusMessageEnum;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author zjq
 * @ClassName:UserInfoController
 * @Description:用户详情
 * @date 2021/4/6 20:02
 **/

@RestController
@Slf4j
@Api(tags = "用户详情接口信息")//用于描述接口类的相关信息，作用于类上
@RequestMapping("/user-info")
public class UserInfoController {

    @Resource
    UserInfoService userInfoService;

    //    购物车
    @Resource
    ShoppingcartService shoppingcartService;

    //数据统计
    @Resource
    StatisticsService statisticsService;


    //    收货地址
    @Resource
    ShippingaddressService shippingaddressService;


    /*
     * 功能描述〈查询用户详情信息〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/9 22:51
     * @throws
     */
    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "查询用户详情信息（解析请求头中的token）")

    @ApiResponses(
            @ApiResponse(code = 40012, message = "查询成功", response = UserInfoParam.class)
    )
    @GetMapping("/ordinary/findUserInfoByUserId")
    public Result findUserInfoByUserId() {

        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer userId = Integer.valueOf(String.valueOf(o));

        if (userId != null && userId != 0) {

            UserInfo userInfo = userInfoService.findUserInfo(userId);
            if (ObjectUtil.isNotNull(userInfo)) {
                UserInfoParam one = CopyUtil.getOne(userInfo, UserInfoParam.class);
                return new Result(true, StatusCode.SEARCH_SUCCESSFUL, StatusMessageEnum.SEARCH_SUCCESSFUL.toString(), one);
            }
            return new Result(false, StatusCode.QUERY_IS_EMPTY, StatusMessageEnum.QUERY_IS_EMPTY.toString());
        }


        return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());

    }

    /*
     * 功能描述〈修改用户详情信息〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/9 23:42
     * @throws
     */
    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "修改用户详情信息（解析请求头中的token）")

    @PostMapping("/ordinary/modifyUserInfo")
    public Result modifyUserInfo(@ApiParam @RequestBody UserInfoModifiedParam userInfoModifiedParam) {
        System.out.println(userInfoModifiedParam);
//        解析token
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.ERROR, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer userId = Integer.valueOf(String.valueOf(o));

        if (userId != null && userId != 0) {
            UserInfo one = CopyUtil.getOne(userInfoModifiedParam, UserInfo.class);
            one.setUserId(userId);
//            上传头像,调用MinioController

            userInfoModifiedParam.getUserInfoImage();

//            修改
            log.info("用户" + userId + "开始执行修改");
            Integer integer = userInfoService.modifyUserInfo(one);
            log.info("用户" + userId + "开始执行修改完成");

            return integer > 0 ?
                    new Result(true, StatusCode.OK, StatusMessageEnum.SUCCESSFULLY_MODIFIED.toString())
                    : new Result(true, StatusCode.OK, StatusMessageEnum.FAIL_TO_EDIT.toString());
        }


        return new Result(false, StatusCode.ERROR, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
    }


    //    findOverageByUserId
    /*
     * 功能描述〈查询余额根据用户id〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/15 16:57
     * @throws
     */
    @ApiOperation(value = "查询余额根据用户（订单使用）")
    @GetMapping("/ordinary/findOverageByUserId")
    public Result findOverageByUserId() {
        //        解析token
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);

        Object o = claims.get("token");
        Integer userId = Integer.valueOf(String.valueOf(o));
        BigDecimal overageByUserId = userInfoService.findOverageByUserId(userId);
//        return String.valueOf(overageByUserId);
        return new Result(true, StatusCode.OK, StatusMessageEnum.OK.toString(), overageByUserId);
    }


    /*
     * 功能描述〈用户详情页整合、收藏数、购物车数、余额、卡劵〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/15 15:11
     * @throws
     */
    @ApiOperation(value = "用户详情页整合、收藏数、购物车数、余额、卡劵")

    @PostMapping("/ordinary/totalDetail")
    public Result totalDetail() {
        //        解析token
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);

        Object o = claims.get("token");
        Integer userId = Integer.valueOf(String.valueOf(o));

        UserInfoDto userInfoDto = userInfoService.totalDetail(userId);
        if (ObjectUtil.isNull(userInfoDto)) {
            return new Result(false, StatusCode.QUERY_IS_EMPTY, StatusMessageEnum.QUERY_IS_EMPTY.toString());
        }
        return new Result(true, StatusCode.SEARCH_SUCCESSFUL, StatusMessageEnum.SEARCH_SUCCESSFUL.toString(), userInfoDto);

    }




    /*
     * 功能描述〈用户评论详情〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/16 8:37
     * @throws
     */

    @ApiOperation(value = "用户评论详情（商品调用、门店服务调用）")

    @GetMapping("/userConmmentByUserId")
    public UserCommentDto userConmmentByUserId() {
        //        解析token
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);

        Object o = claims.get("token");
        Integer userId = Integer.valueOf(String.valueOf(o));
        UserCommentDto userCommentDto = userInfoService.userConmmentByUserId(userId);

        return ObjectUtils.isEmpty(userCommentDto) ? null : userCommentDto;
    }


    /*
     * 功能描述〈用户查询购物车〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/12 11:54
     * @throws
     */
    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "用户查询购物车,解析token")
    //@ApiResponses用于描述响应状态信息

    @GetMapping("/ordinary/findShoppingcartByUserId")
    public Result findShoppingcartByUserId() {
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        List<Shoppingcart> shoppingcartByUserId = shoppingcartService.findShoppingcartByUserId(tokenUserId);


        if (ObjectUtil.isNull(shoppingcartByUserId)) {
            return new Result(false, StatusCode.QUERY_IS_EMPTY, StatusMessageEnum.QUERY_IS_EMPTY.toString());
        }

        List<ShoppingcartDto> shoppingcartlist = CopyUtil.getList(shoppingcartByUserId, ShoppingcartDto.class);

        return new Result(true, StatusCode.SEARCH_SUCCESSFUL, StatusMessageEnum.SEARCH_SUCCESSFUL.toString(), shoppingcartlist);
    }

    /*
     * 功能描述〈用户新增购物车〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/13 4:53
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "用户新增购物车")
    //@ApiResponses用于描述响应状态信息

    @PostMapping("/ordinary/addShoppingcartByUserId")

    public Result addShoppingcartByUserId(@ApiParam Shoppingcartparam shoppingcartparam) {
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        Shoppingcart one = CopyUtil.getOne(shoppingcartparam, Shoppingcart.class);
        one.setUserId(tokenUserId);
        log.info("准备执行新增购物车");
        boolean b = shoppingcartService.addShoppingcartByUserId(one);
        log.info("执行新增购物车完毕");
        return b == true ? new Result(true, StatusCode.ADDED_SUCCESSFULLY, StatusMessageEnum.ADDED_SUCCESSFULLY.toString())
                : new Result(true, StatusCode.ADD_FAILED, StatusMessageEnum.ADD_FAILED.toString());
    }

    /*
     * 功能描述〈用户删除购物车〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/13 4:54
     * @throws
     */


    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "用户删除购物车")
    //@ApiResponses用于描述响应状态信息
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shoppingcartId", value = "购物车id"
                    , example = "1", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("/ordinary/deleteShoppingcartByShoppingcartId")
    public Result deleteShoppingcartByShoppingcartId(Integer shoppingcartId) {
        if (shoppingcartId == null && shoppingcartId == 0) {
            new Result(true, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
        }
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        log.info("开始执行删除购物车");
        boolean b = shoppingcartService.deleteShoppingcartByShoppingcartId(shoppingcartId, tokenUserId);
        log.info("开始执行删除购物车完毕");
        return b == true ? new Result(true, StatusCode.SUCCESSFULLY_DELETED, StatusMessageEnum.SUCCESSFULLY_DELETED.toString())
                : new Result(true, StatusCode.FAILED_TO_DELETE, StatusMessageEnum.FAILED_TO_DELETE.toString());
    }



    /*
     * 功能描述〈查询数据统计〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/10 14:41
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "查询用户数据统计（解析token获取）")
    @GetMapping("/ordinary/findStatisticsByUserId")
    public Result findStatisticsByUserId() {
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));

        if (tokenUserId != null && tokenUserId != 0) {
            Statistics statisticsByUserId = statisticsService.findStatisticsByUserId(tokenUserId);
            return ObjectUtil.isNull(statisticsByUserId) ?
                    new Result(false, StatusCode.QUERY_IS_EMPTY, StatusMessageEnum.QUERY_IS_EMPTY.toString())
                    : new Result(true, StatusCode.SEARCH_SUCCESSFUL, StatusMessageEnum.SEARCH_SUCCESSFUL.toString(), statisticsByUserId);
        }
        return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
    }

    /*
     * 功能描述〈修改收藏数〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/10 14:45
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "修改收藏数（解析token获取）点击收藏按钮数量增加")
    @GetMapping("/ordinary/modifyFavorites")
    public Result modifyFavorites() {
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));

        if (tokenUserId != null && tokenUserId != 0) {
            log.info("开始修改收藏数");
            boolean b = statisticsService.modifyFavorites(tokenUserId);
            log.info("开始修改收藏数完毕");
            return b ?
                    new Result(true, StatusCode.SUCCESSFULLY_MODIFIED, StatusMessageEnum.SUCCESSFULLY_MODIFIED.toString())
                    : new Result(false, StatusCode.FAIL_TO_EDIT, StatusMessageEnum.FAIL_TO_EDIT.toString());

        }
        return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
    }

    /*
     * 功能描述〈修改购物车数〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/10 14:45
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "修改修改购物车数（解析token获取）点击加入购物车按钮数量增加")
    @GetMapping("/ordinary/modifyShoppingCart")
    public Result modifyShoppingCart() {
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));

        if (tokenUserId != null && tokenUserId != 0) {
            log.info("开始修改购物车数");
            boolean b = statisticsService.modifyShoppingCart(tokenUserId);
            log.info("开始修改购物车数");
            return b ?
                    new Result(true, StatusCode.SUCCESSFULLY_MODIFIED, StatusMessageEnum.SUCCESSFULLY_MODIFIED.toString())
                    : new Result(false, StatusCode.FAIL_TO_EDIT, StatusMessageEnum.FAIL_TO_EDIT.toString());

        }
        return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
    }


    /*
     * 功能描述〈根据用户查询所有的收货地址〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/12 16:08
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "根据用户查询所有的收货地址,解析token")
    //@ApiResponses用于描述响应状态信息

    @GetMapping("/ordinary/findShippingaddressByUserId")
    public Result findShippingaddressByUserId() {
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.ERROR, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        List<Shippingaddress> shippingaddressByUserId = shippingaddressService.findShippingaddressByUserId(tokenUserId);

        if (ObjectUtil.isNull(shippingaddressByUserId)) {
            return new Result(false, StatusCode.ERROR, StatusMessageEnum.QUERY_IS_EMPTY.toString());
        }

        List<ShippingaddressDto> shippingaddressList = CopyUtil.getList(shippingaddressByUserId, ShippingaddressDto.class);
        if (ObjectUtil.isNull(shippingaddressList)) {
            return new Result(false, StatusCode.QUERY_IS_EMPTY, StatusMessageEnum.QUERY_IS_EMPTY.toString(), shippingaddressList);

        }
        return new Result(true, StatusCode.SEARCH_SUCCESSFUL, StatusMessageEnum.SEARCH_SUCCESSFUL.toString(), shippingaddressList);
    }


    /*
     * 功能描述〈根据用户id查询默认收货地址〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/12 16:01
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上

    @ApiOperation(value = "根据用户id查询默认收货地址,解析token")
    //@ApiResponses用于描述响应状态信息

    @GetMapping("/ordinary/findShippingaddressDefaultByUserId")
    public Result findShippingaddressDefaultByUserId() {
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        Shippingaddress shippingaddressDefaultByUserId = shippingaddressService.findShippingaddressDefaultByUserId(tokenUserId);

        if (ObjectUtil.isNull(shippingaddressDefaultByUserId)) {
            return new Result(false, StatusCode.QUERY_IS_EMPTY, StatusMessageEnum.QUERY_IS_EMPTY.toString());
        }

        ShippingaddressDto findShippingaddressDefault = CopyUtil.getOne(shippingaddressDefaultByUserId, ShippingaddressDto.class);

        return new Result(true, StatusCode.SEARCH_SUCCESSFUL, StatusMessageEnum.SEARCH_SUCCESSFUL.toString(), findShippingaddressDefault);
    }

    /*
     * 功能描述〈修改地址〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/13 5:35
     * @throws
     */
    @ApiOperation(value = "修改地址")
    //@ApiResponses用于描述响应状态信息

    @PostMapping("/ordinary/modifyShippingaddressByshippingaddressId")
    public Result modifyShippingaddressByshippingaddressId(@ApiParam ShippingaddressDto shippingaddressDto) {
        if (ObjectUtil.isNull(shippingaddressDto)) {
            return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
        }
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        boolean b = shippingaddressService.modifyShippingaddressByshippingaddressId(shippingaddressDto);
        return b ?
                new Result(true, StatusCode.SUCCESSFULLY_MODIFIED, StatusMessageEnum.SUCCESSFULLY_MODIFIED.toString())
                : new Result(false, StatusCode.FAIL_TO_EDIT, StatusMessageEnum.FAIL_TO_EDIT.toString());


    }

    /*
     * 功能描述〈删除地址〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/13 8:53
     * @throws
     */
    @ApiOperation(value = "删除地址")
    //@ApiResponses用于描述响应状态信息

    @PostMapping("/ordinary/deleteShippingaddressByshippingaddressId")
    public Result deleteShippingaddressByshippingaddressId(Integer shippingaddressId) {

        if (ObjectUtil.isNull(shippingaddressId)) {
            return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
        }
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        if (ObjectUtil.isNull(shippingaddressId)) {
            return new Result(true, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());

        }
        boolean b = shippingaddressService.deleteShippingaddressByshippingaddressId(shippingaddressId);
        return b ?
                new Result(true, StatusCode.SUCCESSFULLY_DELETED, StatusMessageEnum.SUCCESSFULLY_DELETED.toString())
                : new Result(false, StatusCode.FAILED_TO_DELETE, StatusMessageEnum.FAILED_TO_DELETE.toString());


    }

    /*
     * 功能描述〈新增地址〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/14 20:54
     * @throws
     */
    @ApiOperation(value = "新增地址")
    //@ApiResponses用于描述响应状态信息

    @PostMapping("/ordinary/addShippingaddress")
    public Result addShippingaddress(ShippingaddressParam shippingaddressParam) {
        if (ObjectUtil.isNull(shippingaddressParam)) {
            return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());

        }
        ServletRequestAttributes sra =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        JwtUtil jwtUtil = new JwtUtil();
        Claims claims = jwtUtil.parseTokenOrdinary(token);
        if (claims == null) {

            return new Result(false, StatusCode.NOT_LOGGED_IN, StatusMessageEnum.NOT_LOGGED_IN.toString());
        }
        Object o = claims.get("token");
        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
        Shippingaddress one = CopyUtil.getOne(shippingaddressParam, Shippingaddress.class);
        one.setUserId(tokenUserId);
        Boolean aBoolean = shippingaddressService.addShippingaddress(one);
        return aBoolean ?
                new Result(true, StatusCode.ADDED_SUCCESSFULLY, StatusMessageEnum.ADDED_SUCCESSFULLY.toString())
                : new Result(false, StatusCode.ADD_FAILED, StatusMessageEnum.ADD_FAILED.toString());


    }


    /*
     * 功能描述〈查询多少个用户收藏门店〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/16 14:46
     * @throws
     */
//    statisticsService
    @ApiOperation(value = "查询多少个用户收藏门店(门店调用)")
    @GetMapping("/merchantmanage/addShippingaddress")
    public Integer totalNumberOfStoreCollections(Integer storeId) {
        Integer integer = statisticsService.totalNumberOfStoreCollections(storeId);
        return integer;
    }


}

